package com.xgkj.diyiketang.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xgkj.diyiketang.R;

/**
 * Created by XCKJ_Paladowow on 2016/8/2.
 */
public class ShareLimitActivity extends BaseActivity implements View.OnClickListener {
    private Context mContext;
    private RelativeLayout mGongKaiLayout;
    private RelativeLayout mPYQLayout;
    private RelativeLayout mSelfLayout;
    private CheckBox mGKCheck;
    private CheckBox mPYQCheck;
    private CheckBox mSelfCheck;
    private TextView mBack;
    private String mscope;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sharelimit);
        mContext = this;
        initView();
    }

    private void initView() {
        Intent intent = getIntent();

        mBack = (TextView) findViewById(R.id.back);
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mGongKaiLayout = (RelativeLayout) findViewById(R.id.gongkai_layout);
        mGongKaiLayout.setOnClickListener(this);
        mGKCheck = (CheckBox) findViewById(R.id.checkbox_gk);
        mGKCheck.setClickable(false);
        mPYQLayout = (RelativeLayout) findViewById(R.id.haoyouquan_layout);
        mPYQLayout.setOnClickListener(this);
        mPYQCheck = (CheckBox) findViewById(R.id.checkbox_hyq);
        mPYQCheck.setClickable(false);
        mSelfLayout = (RelativeLayout) findViewById(R.id.myself_layout);
        mSelfLayout.setOnClickListener(this);
        mSelfCheck = (CheckBox) findViewById(R.id.checkbox_myself);
        mSelfCheck.setClickable(false);

        if(intent!=null){
            mscope = intent.getStringExtra("SCOPE");
            if(mscope!=null){
                if(mscope.equals("0")){
                    mGKCheck.setChecked(true);
                }else if(mscope.equals("1")){
                    mPYQCheck.setChecked(true);
                }else if(mscope.equals("2")){
                    mSelfCheck.setChecked(true);
                }
            }
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.gongkai_layout:
                mGKCheck.setChecked(true);
                mPYQCheck.setChecked(false);
                mSelfCheck.setChecked(false);
                Intent intent = new Intent();
                intent.putExtra("LIMIT", "公开");
                intent.putExtra("SCOPE","0");
                //设置返回数据
                ShareLimitActivity.this.setResult(RESULT_OK, intent);
                //关闭Activity
                ShareLimitActivity.this.finish();
                break;
            case R.id.haoyouquan_layout:
                mGKCheck.setChecked(false);
                mPYQCheck.setChecked(true);
                mSelfCheck.setChecked(false);
                Intent intent2 = new Intent();
                intent2.putExtra("LIMIT", "好友圈");
                intent2.putExtra("SCOPE","1");
                //设置返回数据
                ShareLimitActivity.this.setResult(RESULT_OK, intent2);
                //关闭Activity
                ShareLimitActivity.this.finish();
                break;

            case R.id.myself_layout:
                mGKCheck.setChecked(false);
                mPYQCheck.setChecked(false);
                mSelfCheck.setChecked(true);
                Intent intent3 = new Intent();
                intent3.putExtra("LIMIT", "仅自己可见");
                intent3.putExtra("SCOPE","2");
                //设置返回数据
                ShareLimitActivity.this.setResult(RESULT_OK, intent3);
                //关闭Activity
                ShareLimitActivity.this.finish();
                break;
        }
    }
}
